<?php
class ConvertController extends ezcMvcController
{
	public function doConvert()
	{
		$ret = new ezcMvcResult;

		$fileName = 'var/export/ndd-schema.xml';
		$fileNameDb = 'var/export/ndd-schema.sql';

		//mkdir ("var/export", 0777);
		file_put_contents($fileName,'');

		// create a database schema from a database connection:
		$db = ezcDbFactory::create( 'mysql://root@localhost/ndd' );
		$dbSchema = ezcDbSchema::createFromDb( $db );
		
		// save a database schema to an XML file:
		$dbSchema->writeToFile( 'xml', $fileName );

		//save sql to a file
		$sql = '';
		foreach ( $dbSchema->convertToDDL( $db ) as $sqlStatement )
		{
			$sql .= $sqlStatement. "\n";
		}
		
		file_put_contents($fileNameDb,$sql);

		return $ret;
	}
}

?>